package com.hit.aircraftwar.supply;

import com.hit.aircraftwar.activity.MainActivity;
import com.hit.aircraftwar.basic.AbstractFlyingObject;

public abstract class AbstractSupply extends AbstractFlyingObject {
    //效果指数
    protected int effect;

    public abstract void effectActive();

    public AbstractSupply(int locationX, int locationY, int effect) {
        super(locationX,locationY,0,0);
        this.effect = effect;
         //随机方向的速度，纵向额外加速
        double deg = (Math.random()*Math.PI);
        //补给飞行速度
        int speedOverAll = 36;
        this.speedX = (int)((Math.cos(deg)) * speedOverAll);
        this.speedY = (int)((Math.sin(deg)) * speedOverAll + 8);
    }

    @Override
    public void forward() {
        locationX += speedX;
        locationY += speedY;
        if (locationY <= 0) {
            //上出界则反弹
                speedY = -speedY;
        }
        else if(locationY >= MainActivity.height) {
            //下出界则销毁
            vanish();
        }
        if (locationX <= 0 || locationX >= MainActivity.width) {
            //横向出界反弹
            speedX = -speedX;
        }
    }

}
